/**
 * 文件描述如下：
 * 1. pageContorl.js 用于感知效果页面的控制
 * 2. 播放视频 点云 和点云结果 以及视频结果
 * 3. 可以回退和前进
 * 4.
 */

let store,
  index = 0

import { mainStore } from '@store'
import { ElMessage } from 'element-plus'
export const play = () => {
  const store = mainStore()
  store.perceivedEffectStatus = 'play'
  store.videoBoxList.forEach((item) => {
    const element = document.getElementById(`video_${item.id}`)
    element.play()
  })
}
export const pause = () => {
  store = mainStore()
  store.perceivedEffectStatus = 'pause'
  store.videoBoxList.forEach((item) => {
    const element = document.getElementById(`video_${item.id}`)
    element.pause()
  })

  index = store.frameNum - 1
}

/**
 *
 * @number 回退的步数 1 帧 2 满帧
 * @returns
 */
export const backspace = (number) => {
  if (index <= 0) return ElMessage.info(`当前已经是第一帧`)

  index = number == 1 ? (index -= 1) : (index = 0)


  const pcdHistory = store.pcdHistory[index]

  if (!pcdHistory) return ElMessage.error(`历史留存数据不足${store.frameNum}帧率`)
  store.carData = pcdHistory
  // window.updatePointsResult(store.pcdResult)
}

export const next = (number) => {
  if (index >= store.frameNum - 1) return ElMessage.info(`当前已经是最后一帧`)

  index = number == 1 ? (index += 1) : store.frameNum - 1

  const pcdHistory = store.pcdHistory[index]
  if ( !pcdHistory) return ElMessage.error(`历史数据不足${store.frameNum}帧`)

  store.carData = pcdHistory
  
}
